<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>JavaScript MVC</title>
   <script type="text/javascript">
       function Model(value){
           this._value=typeof value==='undefined'?'':value;
           this._listance=[];
       }
        /*Model函数注册原型 setTimeout 定时器  不保证到时间一定调用 */
       Model.prototype.set=function(value){
           var self=this;
           self._value=value;
           setTimeout(function(){
              self._listance.forEach(function(listener)){
                 listener.call(self,value);
               };
           });
       };
       Model.prototype.watch=function(listener){
           //注册监听回调函数
            this._listance.push(listener);
       };
       (function(){
           var model=Model();
           var div1=document.getElementById("div1");
           model.watch(function(value){
               div1.innerHTML=value;
           });
           model.set("helow world!!")
       })()
   </script>
</head>
<body>
<div class="div1">div1</div>
</body>
</html>